package jannex.mapping;

public final class MappingModifiers {

    private MappingModifiers() {}

    public static final int ID = 1;
    public static final int UPDATABLE = 2;
    public static final int SELECTABLE = 4;
    public static final int INSERTABLE = 8;


    public static final int DEFAULTS = UPDATABLE | SELECTABLE | INSERTABLE;

    public static boolean isId(int mod) {
        return (mod & ID) != 0;
    }

    public static boolean isUpdatable(int mod) {
        return (mod & UPDATABLE) != 0;
    }

    public static boolean isSelectable(int mod) {
        return (mod & SELECTABLE) != 0;
    }

    public static boolean isInsertable(int mod) {
        return (mod & INSERTABLE) != 0;
    }

    public static int all(int... mods) {
        int res = 0;
        for (int mod : mods) {
            res |= mod;
        }
        return res;
    }

    public static String describe(int mod) {
        StringBuilder builder = new StringBuilder();
        for (String str : new String[] {"Id", "Unique", "Updatable", "Selectable", "Insertable"}) {
            if ((mod & 1) != 0) {
                builder.append(str).append(", ");
            }
            mod = mod >> 1;
            if (mod == 0) {
                break;
            }
        }
        if (builder.length() > 2) {
            builder.delete(builder.length()-2, builder.length());
        }
        return builder.toString();
    }

}
